package com.qianji.service.impl;

import cn.hutool.core.date.DateTime;
import com.qianji.mapper.PrizeMapper;
import com.qianji.pojo.ActiveDto;
import com.qianji.pojo.PrizeDto;
import com.qianji.service.PrizeService;
import com.qianji.utils.Result;
import com.qianji.vo.PrizeAddVO;
import com.qianji.vo.PrizeUpdateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 阳家桂 on 2021/3/12 15:39
 */
@Service
public class PrizeServiceImpl  implements PrizeService {

    @Autowired
    private PrizeMapper prizeMapper;

    /**
     * 添加奖品
     * @param prizeAddVO
     * @return
     */
    @Override
    public Integer addPrize(PrizeAddVO prizeAddVO) {

        prizeAddVO.setCreateTime(new DateTime());
        return prizeMapper.addPrize(prizeAddVO);
    }


    /**
     * 删除奖品
     * @param
     * @return
     */
    @Override
    public Integer updatePrize(PrizeUpdateVO prizeUpdateVO ) {
        prizeUpdateVO.setUpdateTime(new DateTime());
        return prizeMapper.updatePrize(prizeUpdateVO);
    }

    /**
     * 查询所有奖品
     * @param prizeDto
     * @return
     */
    @Override
    public Result selectAll(PrizeDto prizeDto) {
        //获取当前页数
        prizeDto.setPage((prizeDto.getPage()-1)* prizeDto.getLimit());

        List<PrizeDto> prizeDtoList = prizeMapper.selectAll(prizeDto);
        //总数据条数
        Long count = prizeMapper.count(prizeDto);
        return Result.success(prizeDtoList,count);
    }
}
